package com.android.lomabun;

import android.app.Activity;
import android.os.Bundle;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import android.util.Log;
public class Lomabun extends Activity {
    private BufferedReader input;
    private PrintWriter output;
    private boolean started = false;

    private ServerSocket serverSocket;
    private Socket clientSocket;
    private int port = 7788;
    private String TAG = "Lomabun";
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);
        // Only bind this to local host.  This means that you can only
        // talk to the monkey locally, or though adb port forwarding.
        try {
        	Log.v(TAG, "log1");
    	   serverSocket = new ServerSocket(port,
                                        0, // default backlog
                                        InetAddress.getLocalHost());
    	 Log.v(TAG, "log2");
    	 /**
         * Start a network server listening on the specified port.  The
         * network protocol is a line oriented protocol, where each line
         * is a different command that can be run.
         *
         * @param port the port to listen on
         */
           Log.v(TAG, "log3");
            clientSocket = serverSocket.accept();
            // At this point, we have a client connected.  Wake the device
            // up in preparation for doing some commands.
            //wake();
            Log.v(TAG, "log4");
            input = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
            // auto-flush
            output = new PrintWriter(clientSocket.getOutputStream(), true);
            String s="gggggggggg";
           while ((s = input.readLine()) != null) {
                Log.v(TAG, s);
                output.println("OK");
           }
        }catch(IOException e){
        	Log.v(TAG, e.getMessage());
        }
        

   
    }

}